package SimulateServer// ActionScript file
{
	import Classes.GameErrors.GameError;

	public class ServerMsgDeal
	{
		private static var _instance:ServerMsgDeal;/*静态引用*/
		private var _msgNumCount:int;/*消息号计数器*/
		private var _baseData:Object;
		private var _sundriesAry:Array;
		private var _zombiesAry:Array;
		private var _buildingsAry:Array;
		private var _decorationsAry:Array;
		private var _sickMansAry:Array;
		private var _itemsAry:Array;
		private var _wallsAry:Array;
		private var _achievesAry:Array;
		private var _friendsAry:Array;
		private var _missionsAry:Array;
		private var _mealMenusAry:Array;
		private var _albumsAry:Array;
		private var _picsAry:Array;
		private var _puzzlesAry:Array;
		private var _equiptsAry:Array;
		private var _storeBuildingsAry:Array;
		public function ServerMsgDeal():void
		{
			_instance=this;
			this.init();
		}
		
		private function init():void
		{
			var i:int;
			this._baseData=
				{
					playerName:"测试玩家",
					playerViewID:0,
					playerJob:0,
					playerSex:false,
					playerLv:1,
					playerExp:0,
					money:100,
					gold:100,
					actPoint:10,
					playerLife:5,
					centerLv:1,
					havenState:false
				};
			this._sundriesAry=new Array;
			this._zombiesAry=new Array;
			this._buildingsAry=new Array;
			this._decorationsAry=new Array;
			this._sickMansAry=new Array;
			this._itemsAry=new Array;
			this._wallsAry=new Array;
			this._achievesAry=new Array;
			this._friendsAry=new Array;
			this._mealMenusAry=new Array;
			this._albumsAry=new Array;
			this._picsAry=new Array;
			this._puzzlesAry=new Array;
			this._equiptsAry=new Array;
			this._missionsAry=new Array;
			this._storeBuildingsAry=new Array;
			for(i=0;i<50;i++)
			{
				var randomZombieAry:Array=[20100001,20100002,20100003]
				var randomZombieType:int=randomZombieAry[int(randomZombieAry.length*Math.random())];
				var zombieObj:Object={zombieID:i+1,zombieType:randomZombieType,life:3};
				this.zombiesAry.push(zombieObj);
			}
			for(i=0;i<72;i++)
			{
				this.wallsAry.push({wallSerial:i,type:1,dur:int(Math.random()*3)});
			}
			this.itemsAry.push({itemType:"13000001",itemNum:1});
			this.itemsAry.push({itemType:"13000002",itemNum:1});
			this.itemsAry.push({itemType:"13000003",itemNum:1});
			this.itemsAry.push({itemType:"13000004",itemNum:3});
			this.itemsAry.push({itemType:"13000005",itemNum:1});
			this.itemsAry.push({itemType:"13000011",itemNum:1});
			this.itemsAry.push({itemType:"13000012",itemNum:1});
			this.itemsAry.push({itemType:"13000013",itemNum:1});
			this.buildingsAry.push({buildingID:1,buildingType:40101001,buildingLv:1,coordinate:16884});
			this.buildingsAry.push({buildingID:2,buildingType:40103001,buildingLv:1,coordinate:20100});
			/*sundryID
			sundryType
			sundryDur
			coordinate*/			
			/*this.sundriesAry.push({sundryID:1,sundryType:30000008,sundryDur:60,coordinate:0});
			this.sundriesAry.push({sundryID:2,sundryType:31000006,sundryDur:10,coordinate:4200});
			this.sundriesAry.push({sundryID:3,sundryType:30000008,sundryDur:30,coordinate:5600});
			this.sundriesAry.push({sundryID:4,sundryType:30000001,sundryDur:60,coordinate:10400});
			this.sundriesAry.push({sundryID:5,sundryType:30000002,sundryDur:60,coordinate:10408});
			this.sundriesAry.push({sundryID:6,sundryType:30000001,sundryDur:40,coordinate:10416});
			this.sundriesAry.push({sundryID:7,sundryType:30000002,sundryDur:40,coordinate:10424});
			this.sundriesAry.push({sundryID:8,sundryType:30000001,sundryDur:20,coordinate:10432});
			this.sundriesAry.push({sundryID:9,sundryType:30000002,sundryDur:20,coordinate:10440});
			this.sundriesAry.push({sundryID:10,sundryType:30000008,sundryDur:60,coordinate:21400});*/
			this.sundriesAry.push({sundryID:11,sundryType:31000006,sundryDur:10,coordinate:8040});
			this.sundriesAry.push({sundryID:12,sundryType:31000010,sundryDur:30,coordinate:9040});
			/*this.sundriesAry.push({sundryID:13,sundryType:30000001,sundryDur:60,coordinate:30400});
			this.sundriesAry.push({sundryID:14,sundryType:30000002,sundryDur:60,coordinate:30408});
			this.sundriesAry.push({sundryID:15,sundryType:30000001,sundryDur:40,coordinate:30416});
			this.sundriesAry.push({sundryID:16,sundryType:30000002,sundryDur:40,coordinate:30424});
			this.sundriesAry.push({sundryID:17,sundryType:30000001,sundryDur:20,coordinate:30432});
			this.sundriesAry.push({sundryID:18,sundryType:30000002,sundryDur:20,coordinate:30440});*/
			//this.missionsAry.push({missionID:1,missionType:10000102,countsAry:null});
			//this.missionsAry.push({missionID:2,missionType:10000301,countsArt:null});
			this.storeBuildingsAry.push({buildingType:40103001,buildingNum:1})
		}
		
		public function dealMsg(msgObj:Object):Object
		{
			var returnObj:Object=new Object;
			switch(msgObj.command)
			{
				case 11000:
					returnObj[this.getMsgNumCount()]={21000:this.return_21000()}
					returnObj[this.getMsgNumCount()]={21001:this.return_21001()};
					break;
				case 11001:
					returnObj[this.getMsgNumCount()]={21002:this.return_21002()};
					break;
				case 12000:
					returnObj[this.getMsgNumCount()]={22700:this.return_22700(msgObj.msgContent)};
					returnObj[this.getMsgNumCount()]={22101:this.return_22101(msgObj.msgContent)};
					break;
				case 12005:
					returnObj[this.getMsgNumCount()]={22005:this.return_22005(msgObj.msgContent)};
					break;
				case 12009:
					returnObj[this.getMsgNumCount()]={24001:this.return_24001()};
					break;
				case 13000:
					returnObj[this.getMsgNumCount()]={24002:this.return_24002()};
					break;
			}
			return returnObj;
		}

		private function getRewardsAry():Array
		{
			var returnAry:Array=new Array;
			var randomNum:int=Math.random()*4+1;
			for(var i:int=0;i<randomNum;i++)
			{
				var rewardObj:Object={rewardType:1,rewardPar1:0,rewardPar2:0};
				returnAry.push(rewardObj);
			}
			return returnAry;
		}
		
		private function return_21000():Object
		{
			var returnObj:Object=new Object;
			returnObj.userID=1;
			return returnObj;
		}
		
		private function return_21001():Object
		{
			var returnObj:Object=new Object;
			returnObj.serverTime=0;
			return returnObj;
		}
		
		private function return_21002():Object
		{
			var returnObj:Object=new Object;
			returnObj.baseData=this.baseData;
			returnObj.sundriesAry=this.sundriesAry;
			returnObj.zombiesAry=this.zombiesAry;
			returnObj.buildingsAry=this.buildingsAry;
			returnObj.decorationsAry=this.decorationsAry
			returnObj.sickMansAry=this.sickMansAry;
			returnObj.itemsAry=this.itemsAry;
			returnObj.wallsAry=this.wallsAry;
			returnObj.achievesAry=this.achievesAry;
			returnObj.friendsAry=this.friendsAry;
			returnObj.mealMenusAry=this.mealMenusAry;
			returnObj.albumsAry=this.albumsAry;
			returnObj.picsAry=this.picsAry;
			returnObj.puzzlesAry=this.puzzlesAry;
			returnObj.equiptsAry=this.equiptsAry;
			returnObj.missionsAry=this.missionsAry;
			returnObj.storeBuildingsAry=this.storeBuildingsAry;
			return returnObj;
		}
		
		private function return_22005(contentObj:Object):Object
		{
			var returnObj:Object=new Object;
			if(this.baseData.playerLife)this.baseData.playerLife-=1;
			returnObj.value=this.baseData.playerLife;
			return returnObj;
		}
		
		private function return_22101(contentObj:Object):Object
		{
			var returnObj:Object=new Object;
			var zombieObj:Object=this.getZombieObjByID(contentObj.zombieID);
			if(!zombieObj)throw new GameError("该僵尸不存在");
			zombieObj.life-=1;
			returnObj.zombieID=contentObj.zombieID;
			returnObj.value=zombieObj.life;
			return returnObj;
		}
		
		private function return_22700(contentObj:Object):Object
		{
			var returnObj:Object=new Object;
			returnObj.dropTargetType="201";
			returnObj.dropTargetPar=contentObj.zombieID;
			returnObj.dropAry=new Array;
			var dropNum:int=Math.random()*5+1;
			for(var i:int=0;i<dropNum;i++)
			{
				var dropType:int=Math.random()*4+1;
				var dropPar:int=0;
				(returnObj.dropAry as Array).push({type:dropType,par:dropPar});
			}
			var dropItemsAry:Array=["13000001","13000002","13000003","13000004","13000005","13000011","13000012","13000013","13000014","13000015"]
			var dropItemType:String=dropItemsAry[int(Math.random()*dropItemsAry.length)];
			(returnObj.dropAry as Array).push({type:0,par:dropItemType});
			return returnObj;
		}
		
		private function return_24001():Object
		{
			this.baseData.playerLife=5;
			var returnObj:Object={value:1};
			return returnObj;
		}
		
		private function return_24002():Object
		{
			var returnObj:Object={value:1};
			return returnObj;
		}
		
		public function getZombieObjByID(zombieID:int):Object
		{
			for(var i:int=0;i<this.zombiesAry.length;i++)
			{
				var checkZombieObj:Object=this.zombiesAry[i];
				if(checkZombieObj.zombieID==zombieID)
				{
					return checkZombieObj;
				}
			}
			return null;
		}
		
		private function getMsgNumCount():int
		{
			this.msgNumCount+=1;
			return this.msgNumCount;
		}

		/*getter & setter*/
		public static function get instance():ServerMsgDeal
		{
			return _instance;
		}

		public function get zombiesAry():Array
		{
			return _zombiesAry;
		}

		public function get baseData():Object
		{
			return _baseData;
		}

		public function get buildingsAry():Array
		{
			return _buildingsAry;
		}

		public function get decorationsAry():Array
		{
			return _decorationsAry;
		}

		public function get sickMansAry():Array
		{
			return _sickMansAry;
		}

		public function get itemsAry():Array
		{
			return _itemsAry;
		}

		public function get wallsAry():Array
		{
			return _wallsAry;
		}

		public function get achievesAry():Array
		{
			return _achievesAry;
		}

		public function get friendsAry():Array
		{
			return _friendsAry;
		}

		public function get mealMenusAry():Array
		{
			return _mealMenusAry;
		}

		public function get albumsAry():Array
		{
			return _albumsAry;
		}

		public function get picsAry():Array
		{
			return _picsAry;
		}

		public function get puzzlesAry():Array
		{
			return _puzzlesAry;
		}

		public function get equiptsAry():Array
		{
			return _equiptsAry;
		}

		public function get sundriesAry():Array
		{
			return _sundriesAry;
		}

		public function get missionsAry():Array
		{
			return _missionsAry;
		}

		public function get storeBuildingsAry():Array
		{
			return _storeBuildingsAry;
		}

		public function get msgNumCount():int
		{
			return _msgNumCount;
		}

		public function set msgNumCount(value:int):void
		{
			_msgNumCount = value;
		}


	}
}